package day_2023_7_to_10;

import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

/**
 * @author haomin
 * @date 2023/07/31 23:06
 **/
public class Day_7_31 {
    class Solution {
        public char firstUniqChar(String s) {
            int[] arr = new int[26];
            for (char c : s.toCharArray()) {
                int index = c - 97;
                arr[index] ++;
            }
            for (char c : s.toCharArray()) {
                int index = c - 97;
                if (arr[index] == 1) return c;
            }
            return ' ';
        }
    }
    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     int val;
     *     TreeNode left;
     *     TreeNode right;
     *     TreeNode(int x) { val = x; }
     * }
     */
    class Solution2 {
        public int[] levelOrder(TreeNode root) {
            if(root == null) return new int[0];
            List<Integer> res = new LinkedList<>();
            Deque<TreeNode> q = new LinkedList<>();
            q.offer(root);
            while(!q.isEmpty()) {
                int size = q.size();
                for(int i = 0; i < size; ++i) {
                    TreeNode cur = q.poll();
                    res.add(cur.val);
                    if (cur.left != null) q.offer(cur.left);
                    if (cur.right != null) q.offer(cur.right);
                }
            }
            return res.stream().mapToInt(Integer::intValue).toArray();
        }
    }
}